package com.wwp.tbshop.model.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import com.wwp.tbshop.view.fragment.HomeFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ${wenping} on 6/15/2017.
 */

public class HomePagerAdapter extends PagerAdapter{
    private HomeFragment mHomeFragment;

    public HomePagerAdapter(HomeFragment homeFragment) {
        mHomeFragment = homeFragment;
    }
    private List<View> mDatas = new ArrayList<>();

    public void setDatas(List<View> datas) {
        mDatas = datas;
    }
    //用于控制到底能显示几张View
    @Override
    public int getCount() {
        return Integer.MAX_VALUE/2;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = mDatas.get(position%mDatas.size());
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        container.removeView(mDatas.get(position%mDatas.size()));
    }
}
